package com.yj_app.qualitytest.util;
/*
 * @Author Hu
 * @Emil 87683202@qq.com
 * Create at 2019/3/28 - 8:24
 * Description:
 */

import java.net.ConnectException;
import java.net.HttpRetryException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

import javax.security.auth.login.LoginException;

public class MyException {


    public static void doException(Exception e) {
        e(e);
    }

    public static void doException(Throwable exception) {

        e(exception);
    }

    private static void e(Throwable e) {
        if (e instanceof UnknownHostException || e instanceof ConnectException) {
            ToastUtils.toastError("网络连接失败，请连接网络....",true);
        } else if (e instanceof SocketTimeoutException) {
            ToastUtils.toastError("网络请求超时",true);
        } else if (e instanceof HttpRetryException) {
            ToastUtils.toastError("服务器拒绝请求",true);
        } else if (e instanceof SocketException) {
            ToastUtils.toastError("网络请求取消！",true);
        } else if (e instanceof LoginException) {
            ToastUtils.toastError(e.getMessage(),true);
        } else {
            ToastUtils.toastError("网络错误！" + e,true);
        }
    }


}
